import requests
import execjs

with open("核心.js") as f:
    js_code = f.read()

js_compile = execjs.compile(js_code)

data = '{"comm":{"cv":4747474,"ct":24,"format":"json","inCharset":"utf-8","outCharset":"utf-8","notice":0,"platform":"yqq.json","needNewCode":1,"uin":497990850,"g_tk_new_20200303":991603224,"g_tk":991603224},"req_1":{"module":"music.musicsearch.HotkeyService","method":"GetHotkeyForQQMusicMobile","param":{"searchid":"18643160291120552","remoteplace":"txt.yqq.top","from":"yqqweb"}}}'
sign = js_compile.call('get_sign',data)
# print(sign)
cookies = {
    'pgv_pvid': '3812685955',
    'fqm_pvqid': 'c525a14a-e3c5-4c5d-aa23-7245e333ba3c',
    'fqm_sessionid': 'b7c21001-03b3-47ff-b404-cdb94c6c5865',
    'pgv_info': 'ssid=s4050235212',
    'ts_refer': 'music.qq.com/',
    'ts_uid': '5816620036',
    '_qpsvr_localtk': '0.9037766922642547',
    'RK': 'aFudm1d5Gf',
    'ptcz': 'd20016b5135a8474d31faf9c71f3d6e0649a96d60b5ae0ac66de7fcaa352133d',
    'login_type': '1',
    'psrf_access_token_expiresAt': '1707492414',
    'euin': '7eElNKEzNe4z',
    'psrf_qqrefresh_token': 'E26D8C4D2AF6DBF4965F872CB44AD53D',
    'wxopenid': '',
    'psrf_qqaccess_token': 'AC6D852A04ADA79E98D0B222F95E0BD3',
    'uin': '497990850',
    'psrf_qqunionid': 'D2F4BCF08E5D3886234D221F5C8970AE',
    'psrf_musickey_createtime': '1699716414',
    'qm_keyst': 'Q_H_L_5DQ3u6qX-zGAxmNNyai2cyRBEGIcftfoWVZgJyK9tXX1wzjapI9CUCQ',
    'wxrefresh_token': '',
    'music_ignore_pskey': '202306271436Hn@vBj',
    'psrf_qqopenid': 'CB541A29C1182BA870FA33CDCBAC6A08',
    'tmeLoginType': '2',
    'qqmusic_key': 'Q_H_L_5DQ3u6qX-zGAxmNNyai2cyRBEGIcftfoWVZgJyK9tXX1wzjapI9CUCQ',
    'wxunionid': '',
    'ts_last': 'y.qq.com/n/ryqq/search',
}

headers = {
    'authority': 'u.y.qq.com',
    'accept': 'application/json',
    'accept-language': 'zh-CN,zh;q=0.9',
    'cache-control': 'no-cache',
    'content-type': 'application/x-www-form-urlencoded',
    # 'cookie': 'pgv_pvid=3812685955; fqm_pvqid=c525a14a-e3c5-4c5d-aa23-7245e333ba3c; fqm_sessionid=b7c21001-03b3-47ff-b404-cdb94c6c5865; pgv_info=ssid=s4050235212; ts_refer=music.qq.com/; ts_uid=5816620036; _qpsvr_localtk=0.9037766922642547; RK=aFudm1d5Gf; ptcz=d20016b5135a8474d31faf9c71f3d6e0649a96d60b5ae0ac66de7fcaa352133d; login_type=1; psrf_access_token_expiresAt=1707492414; euin=7eElNKEzNe4z; psrf_qqrefresh_token=E26D8C4D2AF6DBF4965F872CB44AD53D; wxopenid=; psrf_qqaccess_token=AC6D852A04ADA79E98D0B222F95E0BD3; uin=497990850; psrf_qqunionid=D2F4BCF08E5D3886234D221F5C8970AE; psrf_musickey_createtime=1699716414; qm_keyst=Q_H_L_5DQ3u6qX-zGAxmNNyai2cyRBEGIcftfoWVZgJyK9tXX1wzjapI9CUCQ; wxrefresh_token=; music_ignore_pskey=202306271436Hn@vBj; psrf_qqopenid=CB541A29C1182BA870FA33CDCBAC6A08; tmeLoginType=2; qqmusic_key=Q_H_L_5DQ3u6qX-zGAxmNNyai2cyRBEGIcftfoWVZgJyK9tXX1wzjapI9CUCQ; wxunionid=; ts_last=y.qq.com/n/ryqq/search',
    'origin': 'https://y.qq.com',
    'pragma': 'no-cache',
    'referer': 'https://y.qq.com/',
    'sec-ch-ua': '"Microsoft Edge";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0',
}

params = {
    '_': '1699762740654',
    # 'sign': 'zzb2873897fyflwukqeaf4wsmzzjniwq67fdd41a',
    'sign': sign,
}


response = requests.post('https://u.y.qq.com/cgi-bin/musics.fcg', params=params, cookies=cookies, headers=headers, data=data)
print(response.text)